/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.manager.phase;

import java.io.IOException;
import ru.jSkyRoom.interfaces.JSkyMod;
import ru.jSkyRoom.manager.ModManager;
import ru.jSkyRoom.support.GrupTypeBuilder;
import skyproc.GRUP_TYPE;
import skyproc.SPGlobal;
import skyproc.exceptions.BadMod;
import skyproc.exceptions.MissingMaster;

/**
 *
 * @author Rakev
 */
public class ImportingModsForEditingModPahase extends ImportingModPhase {

    private final String editingModName;

    public ImportingModsForEditingModPahase(String editingModName) {
        this.editingModName = editingModName;
    }

    @Override
    public void importAllMods(GRUP_TYPE... grupTargets) throws IOException, MissingMaster {
        try {
            super.importAllMods(grupTargets); //To change body of generated methods, choose Tools | Templates.
            done();
        } catch (BadMod ex) {
            SPGlobal.logError("Importer", "Skipping a bad mod: " + editingModName);
            SPGlobal.logError("Importer", "  " + ex.toString());
        }
    }

    @Override
    public ImportingModsForEditingModPahase importActiveMods(GRUP_TYPE... grupTargets) throws IOException, MissingMaster {
        super.importActiveMods(grupTargets); //To change body of generated methods, choose Tools | Templates.
        return this;
    }

    @Override
    public ImportingModsForEditingModPahase importMod(String importingMod, GRUP_TYPE... grupTargets) throws BadMod, MissingMaster {
        super.importMod(importingMod, grupTargets); //To change body of generated methods, choose Tools | Templates.
        return this;
    }

    public void done() throws BadMod, MissingMaster {
        GRUP_TYPE[] grupTypes = new GrupTypeBuilder().All().build();
        JSkyMod modBridge = getModImporter().importMod(editingModName, grupTypes);
        getModManager().setActiveMod(modBridge);
    }

    private ModManager getModManager() {
        return ModManager.getInstance();
    }

}
